Skip to content

Fixed path-relativization error when traversing different partitions #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2020

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Apr 14, 2020

It happened on MacOSX, but I do not exclude it may happen in other OS too: when building some large sketch for Arduino Due, the system libsam_xxx.a library is transformed to relative path, in particular the path

/Users/cmaglie/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a

is made relative to the build folder

/var/folder/x8/ttjf_wrd63823894128467832/T/arduino_build_988374/

but since both paths resides in different partitions the result is:

../../../../../../Users/cmaglie/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a

so it traverse from /var/..../arduino_build_988374 to the root and descend back into /Users/...

This is bad for two reasons:

  1. the resulting "relative" path is longer than the original "absolute" path, defeating the purpose of the transformation.

  2. for some weird reason gcc is unable to find the libsam file using the relative path. It seems that when running inside /var/... it cannot "escape" to /Users/...

This patch avoid the situation above by adding a check for the presence of .. in the resulting path (basically avoiding path relativization outside of the build folder) and by checking that the resulting path is shorter than the original absolute path.

It happened on MacOSX, but I do not exclude it may happen in other OS
too: when building some large sketch for Arduino Due, the system libsam_xxx.a
library is transformed to relative path, in particular the path

/Users/cmaglie/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a

is made relative to the build folder

/var/folder/x8/ttjf_wrd63823894128467832/T/arduino_build_988374/

but since both paths resides in different partitions the result is:

../../../../../../Users/cmaglie/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a

so it traverse from /var/..../arduino_buil_988374 to the root and descend back into /Users

This is bad for two reasons:

1) the resulting "relative" path is longer than the original "absolute"
path, defeating the purpose of the transformation.

2) for some weird reason gcc is unable to find the libsam file using the
relative path. It seems that when running inside /var/... it cannot "escape" to
/Users/...

This patch avoid the situation above by adding a check for the presence
of ".." in the resulting path (basically avoiding path relativization
outside of the build folder) and by checking that the resulting path is
shorter than the original absolute path.
@cmaglie cmaglie self-assigned this Apr 14, 2020
@rsora rsora merged commit ad4cb76 into arduino:master Apr 15, 2020
@cmaglie cmaglie added this to the 0.10.0 milestone Apr 15, 2020
@cmaglie cmaglie deleted the fix-path-relativization branch April 15, 2020 15:09
rsora pushed a commit that referenced this pull request Apr 16, 2020
…658)

It happened on MacOSX, but I do not exclude it may happen in other OS
too: when building some large sketch for Arduino Due, the system libsam_xxx.a
library is transformed to relative path, in particular the path

/Users/cmaglie/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a

is made relative to the build folder

/var/folder/x8/ttjf_wrd63823894128467832/T/arduino_build_988374/

but since both paths resides in different partitions the result is:

../../../../../../Users/cmaglie/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a

so it traverse from /var/..../arduino_buil_988374 to the root and descend back into /Users

This is bad for two reasons:

1) the resulting "relative" path is longer than the original "absolute"
path, defeating the purpose of the transformation.

2) for some weird reason gcc is unable to find the libsam file using the
relative path. It seems that when running inside /var/... it cannot "escape" to
/Users/...

This patch avoid the situation above by adding a check for the presence
of ".." in the resulting path (basically avoiding path relativization
outside of the build folder) and by checking that the resulting path is
shorter than the original absolute path.
cmaglie added a commit to arduino/arduino-builder that referenced this pull request Jun 12, 2020
- Removed automatic '--relax' hack for compiles on Atmega2560 MCU
  arduino/arduino-cli#749

- Fixed skethbook+bootloader hex merger.
  arduino/arduino-cli#744

- Fixed race condition in legacy i18n.LoggerToCustomStreams
  arduino/arduino-cli#704

- Fixed path-relativization error when traversing different partitions
  arduino/arduino-cli#658

- Add macro during lib discovery phase
  arduino/arduino-cli#633

- legacy: Improved progress report from Compile
  arduino/arduino-cli#625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants